package com.sub.service.impl;

import com.sub.mapper.SpThirdMenuMapper;
import com.sub.model.SpThirdMenu;
import com.sub.service.ThirdMenuService;
import com.sub.utils.PageList;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ThirdMenuServiceImpl implements ThirdMenuService{

	@Autowired
	private SpThirdMenuMapper spThirdMenuMapper;

	@Autowired
	private Sid sid;

	@Override
	public List<SpThirdMenu> queryThirdMenuList(SpThirdMenu thirdMenu) {
		return spThirdMenuMapper.select(thirdMenu);
	}

	@Override
	public PageList queryThirdMenuByPageAndName(PageList pageList,int page, String name) {
		int size = pageList.getSize();
        pageList.setTotal(spThirdMenuMapper.selectCountS(name));
        pageList.setList(spThirdMenuMapper.getThirdMenuForPage(name,(page-1)*size,size));
		return pageList;
	}

	@Override
	public int saveThird(SpThirdMenu thirdMenu) {
		thirdMenu.setSpThirdMenuId(sid.nextShort());
		return spThirdMenuMapper.insert(thirdMenu);
	}

	@Override
	public int editThird(SpThirdMenu thirdMenu) {
		return spThirdMenuMapper.updateByPrimaryKeySelective(thirdMenu);
	}

	@Override
	public int removeThirdById(String thirdMenuId) {
		return spThirdMenuMapper.deleteByPrimaryKey(thirdMenuId);
	}

	@Override
	public int batchRemoveThirdByIdS(String[] ids) {
		return spThirdMenuMapper.batchRemoveThirdByIdS(ids);
	}
}
